package com.zuxia.controller;


import com.zuxia.param.ShopPageParam;
import com.zuxia.param.ShopReleasePageParam;
import com.zuxia.service.ShopService;
import com.zuxia.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author laoli
 * @since 2024-11-14
 */
@RestController
@RequestMapping("/shop")
@Api("商品接口")
public class ShopController {
    @Resource
    private ShopService shopService;

    @ApiOperation("商品分页查询")
    @PostMapping("/page")
    public R getShopListPage(@RequestBody ShopPageParam shopPageParam) throws Exception{
        return R.ok().message("商品查询").data("shop-page", shopService.getShopListPage(shopPageParam));
    }

    @ApiOperation("单件商品查询")
    @GetMapping("/single/{id}")
    public R getShopListPage(@PathVariable("id") String id) throws Exception{
        return R.ok().message("商品信息").data("shop-single", shopService.getShopById(id));
    }

    @ApiOperation("商品库存修改")
    @GetMapping("/up/num/{id}/{num}")
    public R upShopNumById(@PathVariable("id") String id,@PathVariable("num") Long num) throws Exception{
        return R.ok().message("修改库存").data("shop-up-num", shopService.upShopNumById(id,num));
    }

    @ApiOperation("商品发布查询")
    @PostMapping("/release")
    public R getShopReleaseListPage(@RequestBody ShopReleasePageParam shopReleasePageParam) throws Exception{
        return R.ok().message("商品查询").data("shop-release-page", shopService.getShopReleaseListPage(shopReleasePageParam));
    }

    @ApiOperation("发布-单查商品")
    @GetMapping("/release/single/{id}")
    public R getShopReleaseById(@PathVariable("id") String id) throws Exception{
        return R.ok().message("商品查询").data("shop-release-single", shopService.getShopReleaseById(id));
    }
}

